package com.tengju.motivation.infrastructure.repository.activity.convert;

import com.tengju.motivation.domain.model.performance.MotivationActivityConfig;
import com.tengju.motivation.domain.model.performance.MotivationActivityConfigId;
import com.tengju.motivation.domain.model.performance.MotivationActivityConfigObjectTypeEnum;
import com.tengju.motivation.domain.shared.IdObject;
import com.tengju.motivation.infrastructure.persistence.mybatis.dataobject.MotivationActivityConfigDO;

import java.util.Optional;

/**
 * @author: 李大仙
 * @date: 2021/7/22 3:09 下午
 */
public class MotivationActivityConfigConvert {

    public static MotivationActivityConfigDO convert(MotivationActivityConfig motivationActivityConfig) {
        return new MotivationActivityConfigDO(
                Optional.ofNullable(motivationActivityConfig.getActivityId()).map(IdObject::getValue).orElse(null),
                motivationActivityConfig.getTitle(),
                Optional.ofNullable(motivationActivityConfig.getObjectType()).map(MotivationActivityConfigObjectTypeEnum::getCode).orElse(null),
                motivationActivityConfig.getRemark(),
                motivationActivityConfig.getStartTime(),
                motivationActivityConfig.getEndTime(),
                motivationActivityConfig.getCreateBy(),
                motivationActivityConfig.getUpdateBy(),
                null,
                null
        );
    }

    public static MotivationActivityConfig convert(MotivationActivityConfigDO motivationActivityConfigDO) {
        if (motivationActivityConfigDO == null){
            return null;
        }
        return new MotivationActivityConfig(
                new MotivationActivityConfigId(motivationActivityConfigDO.getActivityId()),
                motivationActivityConfigDO.getTitle(),
                MotivationActivityConfigObjectTypeEnum.form(motivationActivityConfigDO.getObjectType()),
                motivationActivityConfigDO.getRemark(),
                motivationActivityConfigDO.getStartTime(),
                motivationActivityConfigDO.getEndTime(),
                motivationActivityConfigDO.getCreateBy(),
                motivationActivityConfigDO.getUpdateBy()
        );
    }
}
